﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace MetaVideoEditorEvolved
{
    /// <summary>
    /// Interaction logic for WaitingWindow.xaml
    /// </summary>
    public partial class WaitingWindow : Window, INotifyPropertyChanged
    {
        private string action;

        public string Action
        {
            get
            {
                return this.action;
            }

            set
            {
                this.action = value;
                this.OnPropertyChanged("Action");
            }
        }

        public WaitingWindow()
        {
            InitializeComponent();

            this.Owner = System.Windows.Application.Current.MainWindow;
        }

        public WaitingWindow(Action action, string actionName)
            : this()
        {
            this.action = actionName;

            this.Loaded += (o, args) =>
                {
                    this.DataContext = this;

                    var runAction = new Action(() =>
                    {
                        action.Invoke();

                        this.Dispatcher.Invoke(new Action(() =>
                            {
                                this.Close();
                            }));
                    });

                    runAction.BeginInvoke(null, null);
                };
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
